package com.smvc.handlers;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.smvc.entities.User;

@Controller
@RequestMapping("rest")
public class RestController {
	
	private final String SUCCESS = "success";
	
	@RequestMapping(value="user",method=RequestMethod.POST)
	public String saveUser(User user){
		System.out.println("新增："+user);
		return SUCCESS;
	}
	
	/**
	 * 修改用户
	 * @return
	 */
	@RequestMapping(value="user",method=RequestMethod.PUT)
	public String updateUser(User user){
		System.out.println("修改："+user);
		return SUCCESS;
	}
	
	/**
	 * 查询
	 * @param id
	 * @return
	 */
	@RequestMapping(value="user/{id}",method=RequestMethod.GET)
	public String findUser(@PathVariable("id") int id){
		System.out.println("查询："+id);
		return SUCCESS;
	}
	
	@RequestMapping(value="user",method=RequestMethod.DELETE)
	public String deleteUser(@RequestParam("id")int id){
		System.out.println("删除："+id);
		return SUCCESS;
	}
	
	@RequestMapping(value="user",method=RequestMethod.GET)
	public String findUseParam(@RequestParam("id") int id){
		System.out.println("查询，userparam:"+id);
		return SUCCESS;
	}
}
